package com.event.management.backend.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.event.management.backend.domain.Event;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.time.LocalDateTime;

/**
 * 活动信息数据传输对象
 */
@Data
@ApiModel(value = "活动信息", description = "活动详细信息")
public class EventDTO {
    
    @ApiModelProperty(value = "活动ID")
    private Long id;
    
    @ApiModelProperty(value = "活动标题", required = true)
    @NotBlank(message = "活动标题不能为空")
    private String title;
    
    @ApiModelProperty(value = "活动封面图URL", required = true)
    @NotBlank(message = "活动封面不能为空")
    private String cover;
    
    @ApiModelProperty(value = "活动详情介绍", required = true)
    @NotBlank(message = "活动详情不能为空")
    private String description;
    
    @ApiModelProperty(value = "活动举办地点", required = true)
    @NotBlank(message = "活动地点不能为空")
    private String location;
    
    @ApiModelProperty(value = "活动开始时间", required = true, example = "2023-05-01 14:00:00")
    @NotNull(message = "活动开始时间不能为空")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime startTime;
    
    @ApiModelProperty(value = "活动结束时间", required = true, example = "2023-05-01 16:00:00")
    @NotNull(message = "活动结束时间不能为空")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime endTime;
    
    @ApiModelProperty(value = "活动状态", example = "draft", allowableValues = "draft,online,offline", 
            notes = "只能是draft(草稿)、online(上线)、offline(下线)三种状态之一", required = true)
    @NotBlank(message = "活动状态不能为空")
    @Pattern(regexp = "^(draft|online|offline)$", message = "活动状态只能是draft、online或offline")
    private String status;
    
    @ApiModelProperty(value = "活动状态是否有效", hidden = true)
    @JsonIgnore
    private Boolean validStatus;
    
    @ApiModelProperty(value = "活动须知", required = false)
    @JsonIgnore // 忽略此字段，因为数据库中不存在
    private String notes;
    
    @ApiModelProperty(value = "创建者用户ID")
    private Long creatorId;
    
    @ApiModelProperty(value = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createdAt;
    
    @ApiModelProperty(value = "更新时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updatedAt;
    
    @ApiModelProperty(value = "关联票种数量")
    private Integer ticketCount;
    
    @ApiModelProperty(value = "活动分类", example = "音乐")
    private String category;
    
    @ApiModelProperty(value = "活动标签", example = "爵士,现场,交响乐")
    private String tags;
    
    @ApiModelProperty(value = "浏览量")
    private Integer viewCount;
    
    @ApiModelProperty(value = "推荐分数", notes = "推荐排序权重")
    private Float recommendScore;
    
    /**
     * 验证活动状态是否有效
     * @return 是否有效
     */
    public boolean isValidStatus() {
        if (status == null) {
            return true;
        }
        return Event.EventStatus.DRAFT.equals(status) ||
               Event.EventStatus.ONLINE.equals(status) ||
               Event.EventStatus.OFFLINE.equals(status);
    }
} 